<template>
  <div class="app-container">
    <!-- 添加或修改巡逻任务详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body v-drag-fullscreen>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-row :gutter="20">
                <el-col :span="8" :xs="24">
                <el-form-item label="任务ID" prop="taskId">
                    <el-input v-model="form.taskId" placeholder="请输入任务ID" :disabled="disabled"/>
                </el-form-item>
            </el-col>
                <el-col :span="8" :xs="24">
                <el-form-item label="站点ID" prop="placeId">
                    <el-input v-model="form.placeId" placeholder="请输入站点ID" :disabled="disabled"/>
                </el-form-item>
            </el-col>
                <el-col :span="8" :xs="24">
                <el-form-item label="拍照图片">
                  <imageUpload v-model="form.taskImg"/>
                </el-form-item>
            </el-col>
                    <el-col :span="8" :xs="24">
                <el-form-item label="任务备注" prop="taskRemark">
                    <el-input v-model="form.taskRemark" placeholder="请输入任务备注" :disabled="disabled"/>
                </el-form-item>
            </el-col>
                <el-col :span="8" :xs="24">
                <el-form-item label="巡检状态" prop="state">
                    <el-input v-model="form.state" placeholder="请输入巡检状态" :disabled="disabled"/>
                </el-form-item>
            </el-col>
          </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getCruiserTaskDetail , addCruiserTaskDetail, updateCruiserTaskDetail } from "@/api/waitress/CruiserTaskDetail";

export default {
  name: "CruiserTaskDetailFrom",
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否禁用
      disabled: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        taskId: [
          { required: true, message: "任务ID不能为空", trigger: "blur" }
        ],
        placeId: [
          { required: true, message: "站点ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {

  },
  methods: {
    show(option){
      this.reset();
      this.disabled = option.type == 'VIEW'
      if(option.type=='ADD'){
          this.open = true;
          this.title = "新增巡逻任务详情";
      }else if(option.type == 'UPDATE' || option.type == 'VIEW'){
          getCruiserTaskDetail(option.id).then(response => {
              this.form = response.data;
                                                                                                                                                                                                                                                                                                                                                            
              if(option.type == 'VIEW'){
                  this.title = "查看巡逻任务详情";
              }else{
                  this.title = "修改巡逻任务详情";
              }
              this.open = true;
          });
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.$emit("cancel")
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        taskId: null,
        placeId: null,
        taskImg: null,
        taskRemark: null,
        state: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCruiserTaskDetail(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.cancel()
            });
          } else {
            addCruiserTaskDetail(this.form).then(response => {
              this.msgSuccess("新增成功");
                this.cancel()
            });
          }
        }
      });
    }
  }
};
</script>
